package com.yl.chainStore.control.warehouse

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.control.BaseCtrl
import com.yl.chainStore.entity.pay.SysCompanyPayItem
import com.yl.chainStore.pojo.vo.pay.SystemCompanyPayItemSelectVo
import com.yl.chainStore.pojo.vo.warehouse.WarehouseGoodSupplierSelectVo
import com.yl.chainStore.services.warehouse.IWarehouseService
import com.yl.chainStore.services.IWebCompanyService
import com.yl.chainStore.util.payItemTypeListToTreeSelect
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnSuccess
import com.yl.common.getContext
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.*

/**
 * 仓库管理
 */
@RestController
@RequestMapping("warehouse/")
open class WarehouseController(
	private val iWarehouseService: IWarehouseService,
	private val iWebCompanyService: IWebCompanyService
):BaseCtrl() {

	/**
	 * 获取物品分类树形图
	 */
	@GetMapping("item/typeTree")
	@Transactional
	open fun getItemTypeTree():ResponseBody{
		return returnSuccess(payItemTypeListToTreeSelect(iWarehouseService.getGoodTypeList(getContext().subCompanyId),0L))
	}

	/**
	 * 获取物品类型下拉
	 */
	@GetMapping("getGoodsTypeSelect")
	@Transactional
	open fun getGoodsTypeSelect():ResponseBody{
		val resList = mutableListOf<Map<String,Any>>()
		resList.add(TypeEnum.PAY_ITEM_GOODS.getMap())
		resList.add(TypeEnum.PAY_ITEM_CONSUMABLES.getMap())
		return returnSuccess(resList)
	}

	/**
	 * 物品分页
	 */
	@PostMapping("getGoodPage")
	@Transactional
	open fun getGoodPage(@RequestBody vo: SystemCompanyPayItemSelectVo):ResponseBody{
		vo.haveZeroCount = false
		return returnSuccess(iWarehouseService.getGoodPage(Page<SysCompanyPayItem>(vo.current,vo.size),vo,getContext().subCompanyId))
	}

	/**
	 * 物品分页
	 */
	@PostMapping("getGoodPageHaveZero")
	@Transactional
	open fun getGoodPageHaveZero(@RequestBody vo: SystemCompanyPayItemSelectVo):ResponseBody{
		vo.haveZeroCount = true
		return returnSuccess(iWarehouseService.getGoodPage(Page<SysCompanyPayItem>(vo.current,vo.size),vo,getContext().subCompanyId))
	}

	/**
	 * 获取供应商列表
	 */
	@PostMapping("getSupplier")
	@Transactional
	open fun getSupplierList(@RequestBody vo: WarehouseGoodSupplierSelectVo):ResponseBody{
		return returnSuccess(iWarehouseService.supplierList(vo))
	}

	/**
	 * 获取所有仓库
	 */
	@GetMapping("getWarehouseList")
	@Transactional
	open fun getWarehouseList():ResponseBody{
		return returnSuccess(iWebCompanyService.getWarehouseList(getContext().companyId))
	}

}
